#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>

void
delete__cpp_is_harmful(char *s, int n)
{
	while (s[n-1]) {
		*s = *(s + n);
		++s;
	}
}

double
power_f(double a, int n)
{
	register int ret = a;
	if (n == 0)
		return 1.0;
	else if (n > 0)
		while (--n > 0)
			ret *= a;
	return ret;
}

int
main (int argc, char **argv)
{
	static char polynom[102];
	double x = 0;
	double result = 0, var = 0;
	char *px, *sign;
	int power = 1, k = 1;

	scanf("%s", polynom);
	scanf("%lf", &x);

	while (px = strchr(polynom, 'x'), px != NULL) {
		if (px[1] == '^') {
			power = atoi(px + 2);
			sign = px + 2;
			while (*sign != '-' && *sign != '+' && *sign != 0)
				++sign;
			delete__cpp_is_harmful(px + 1, sign - px - 1);
		}

		if (px > polynom) {
			if (px[-1] == '-') {
				k = -1;
				delete__cpp_is_harmful(px - 1, 2);

			} else if (px[-1] == '+') {
				k = 1;
				delete__cpp_is_harmful(px - 1, 2);

			} else if (px[-1] == '*') {
				sign = px - 2;
				while (sign > polynom && *sign != '-' && *sign != '+')
					--sign;

				(*sign == '-') ? k = -1 * abs(atoi(sign)) : (k = abs(atoi(sign)));
				delete__cpp_is_harmful(sign, px - sign + 1);
			}
		} else {
			delete__cpp_is_harmful(px, 1);
		}
		result += k * power_f(x, power);
		k = power = 1;
	}
	while (strlen(polynom) > 0) {
		result += strtod(polynom, &sign);
		delete__cpp_is_harmful(polynom, sign - polynom);
	}

	printf("%.lf\n", result);
	return 0;
}
